--HEADER Added HasOpenPosition column to [FundBookEntity] table
ALTER TABLE [TradingData].[FundBookEntity]
ADD [HasOpenPosition] BIT NOT NULL DEFAULT 0
GO

UPDATE
fund
SET
fund.HasOpenPosition = (SELECT CASE WHEN (SELECT sum(Quantity) FROM [TradingData].[Trade] WHERE FundBookEntityId=fund.Id) > 0 THEN 1 ELSE 0 END)
FROM
[TradingData].[FundBookEntity] fund